<%
can_edit_parameters = can?(:update, 'devices/parameters')
content_for :title do 'Device ' + @device['_id'] end
%>
<script type="text/javascript">
var pending = {};

$(function() {
  var options = {
    valueNames: ['param-path', 'param-value'],
    page: 4000
  };

  var featureList = new List('device-params', options);
  refreshPending();
});
</script>

<h1>Device: <%= @device['_id'] %></h1>

<%= render partial: 'tags', locals: {tags: @device['_tags'] || []} %>

<%
  to_refresh = {'parameters' => [], 'objects' => [], 'custom_commands' => []}

  for k, v in Rails.configuration.summary_parameters
    if v.is_a?(String)
      if (p = get_param(v, @device)) != nil
        if v.start_with?('_customCommands')
          to_refresh['custom_commands'] << v
        else
          to_refresh['parameters'] << v
        end
      end
    else
      if get_param(v['_object'], @device) != nil
        to_refresh['objects'] << v['_object']
      end
    end
  end
%>
<%= render partial: 'last_inform', locals: {to_refresh: to_refresh} %>
<%= render partial: 'summary_group', locals: {can_edit_parameters: can_edit_parameters, params: Rails.configuration.summary_parameters} %>
<%= render partial: 'tasks' %>

<div style="clear:both;"></div>

<%= render partial: 'params', locals: {can_edit_parameters: can_edit_parameters} %>
<%= render partial: 'commands' %>

<div id="pending">
  <h>Pending tasks</h>
  <ul>
  </ul>
  <div class="buttons">
    <a class="button" href="#" onclick="commitPending();return false;">Commit</a>
    <a href="#" onclick="clearPending();return false;">Cancel</a>
  </div>
</div>
